from core.basehandler import BaseHandler
from core.room import Room
from core.support import get_game
from core.action import Action

class Bus(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room

        # build list of actions
        self.add_action(East)
        self.add_action(West)
    
    def get_description(self):
        if self.has_driver() and not self.is_drivered():
            desc = '''
            You have the bus driver (and a totally awesome one at that, dude)!
            '''
        elif self.is_drivered():
            desc = '''
            The system party bus now has a driver!  You can go places.
            '''
        else:
            desc = "Strange. You've found a system party bus, but the driver appears to be missing...."
        return desc
    
    def get_image(self):
        if self.is_drivered():
            return 'bus_with_driver.png'
        else:
            return 'gone_phishing.png'
    
    def get_image_width(self):
        return 'width=100%'
    
    # report whether this room is illuminated
    # which can happen if the room or player has a lit lamp
    
    def has_driver(self):
        
        game = get_game()
            
        # does the player have ASCII from the register?
        player = game.get_player()
        
        if "busdriver" in player.inventory:
            return True
        # if we get here, player does not have ASCII
        return False
        
    def is_drivered(self):
        
        game = get_game()
        
        # is there a lit lamp in the room itself?
        if 'busdriver' in self.inventory:
            if self.inventory['busdriver'].is_lit:
                return True
        
        # does the player have a lit lamp?
        player = game.get_player()
        if 'busdriver' in player.inventory:
            if player.inventory['busdriver'].is_lit:
                return True
                
        # if we get here, the lamp is not lit
        return False
    
    def has_translator(self):
        
        game = get_game()
            
        # does the player have ASCII from the register?
        player = game.get_player()
        
        if "Translator" in player.inventory:
            return True
        # if we get here, player does not have ASCII
        return False

class BusNoDriverHandler(BaseHandler):
    
    def get_template(self):
        return 'cpu.html'
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return Bus

# define actions for this room

class West(Action):
    def __init__(self):
        Action.__init__(self, "West")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        game = get_game()
        room = game.get_room("busnodriver", Bus)
        if room.has_translator():
            return "Go West"
        else:
            return "10"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'VideoCard'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
        
        # enabled only if room is lit.
    def is_enabled(self):
        if self.room.is_drivered():
            return True
        else:
            return False

class East(Action):
    def __init__(self):
        Action.__init__(self, "East")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        game = get_game()
        room = game.get_room("busnodriver", Bus)
        if room.has_translator():
            return "Go East"
        else:
            return "01"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'cpu'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"